package com.linkelee.server.controller.app;



import com.linkelee.api.model.app.AppUser;
import com.linkelee.api.model.base.JsonResult;
import com.linkelee.api.request.app.AppRegisterRequest;
import com.linkelee.api.service.app.IAppUserService;
import com.linkelee.api.util.ValidatorUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 注册
 *
 * @author lsl 154751575@qq.com
 */
@RestController
@RequestMapping("/app")
@Api("APP注册接口")
public class AppRegisterController {
    @Autowired
    private IAppUserService userService;

    @PostMapping("register")
    @ApiOperation("注册")
    public JsonResult register(@RequestBody AppRegisterRequest request){
        //表单校验
        ValidatorUtils.validateEntity(request);
        AppUser user = new AppUser();
        user.setMobile(request.getMobile());
        user.setUsername(request.getMobile());
        user.setPassword(DigestUtils.sha256Hex(request.getPassword()));
        user.setCreateTime(new Date());
        userService.save(user);
        return JsonResult.ok();
    }
}
